﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UnitTemplates.cs" company="DarkBone">
//   DarkBone
// </copyright>
// <summary>
//   Collection of Unit Templates
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DarkBone.Engine.Collections
{
   using System;
   using System.Drawing;
   using System.Drawing.Drawing2D;
   using System.Drawing.Imaging;
   using System.IO;
   using System.Linq;

   using DarkBone.Engine.SC2;

   /// <summary>
   ///   Template alloc
   /// </summary>
   public sealed class UnitTemplates
   {
      #region Constants and Fields

      /// <summary>
      ///   The unit names.
      /// </summary>
      private static readonly string[] unitNames = 
      {
         "Nexus", "Pylon", "Assimilator", "Gateway", "Warp Gate", "Forge", 
         "Photon Cannon", "Cybernetics Core", "Twilight Council", "Stargate",
         "Robotics Facility", "Templar Archive", "Fleet Beacon", 
         "Robotics Bay", "Dark Shrine", "Probe", "Mothership", "Zealot", 
         "Sentry", "Stalker", "High Templar", "Dark Templar", "Archon", 
         "Phoenix", "Void Ray", "Carrier", "Interceptor", "Observer", 
         "Warp Prism", "Immortal", "Colossus", "Hatchery", "Lair", "Hive", 
         "Extractor", "Spawning Pool", "Evolution Chamber", "Spore Crawler", 
         "Roach Warren", "Baneling Nest", "Spine Crawler", "Hydralisk Den", 
         "Infestation Pit", "Spire", "Greater Spire", "Nydus Network", 
         "Ultralisk Cavern", "Larva", "Egg", "Drone", "Overlord", "Overseer",
         "Zergling", "Roach", "Hydralisk", "Infestor", "Changeling", "Infested Terran",
         "Mutalisk", "Corruptor", "Brood Lord", "Ultralisk", "Queen",
         "Command Center", "Orbital Command", "Planetary Fortress", 
         "Refinery", "Supply Depot", "Barracks", "Engineering Bay", "Bunker",
         "Missile Turret", "Sensor Tower", "Ghost Academy", "Factory", 
         "Armory", "Starport", "Fusion Core", "Reactor", "TechLab", "SCV", "MULE", 
         "Marine", "Marauder", "Reaper", "Ghost", "Hellion", "Siege Tank", "Thor", 
         "Viking", "Medivac", "Raven", "Banshee", "Battlecruiser", 
         "Mineral Field", "Rich Mineral Field", "Vespene Geyser", 
         "Xel'Naga Tower"
      };

      /// <summary>
      ///   Unit Templates
      /// </summary>
      private static UnitTemplate.Template[] templates;

      #endregion

      #region Constructors and Destructors

      /// <summary>
      ///   Initializes a new instance of the <see cref = "UnitTemplates" /> class.
      /// </summary>
      public UnitTemplates()
      {
         var i = 0;
         templates = new UnitTemplate.Template[unitNames.Length];
         foreach (var name in unitNames)
         {
            templates[i].FrindlyName = name;
            switch (name)
            {
               case "Nexus":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Pylon":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 2;
                  break;
               case "Assimilator":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(12, 9);
                  templates[i].Priority = 4;
                  break;
               case "Gateway":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Warp Gate":
                  templates[i].Aliases = new[] { name, "WarpGate" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Forge":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Photon Cannon":
                  templates[i].Aliases = new[] { name, "PhotonCannon" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 3;
                  break;
               case "Cybernetics Core":
                  templates[i].Aliases = new[] { name, "CyberneticsCore" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 4;
                  break;
               case "Twilight Council":
                  templates[i].Aliases = new[] { name, "TwilightCouncil" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Stargate":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Robotics Facility":
                  templates[i].Aliases = new[] { name, "RoboticsFacility" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 4;
                  break;
               case "Templar Archive":
                  templates[i].Aliases = new[] { name, "TemplarArchive" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;
               case "Fleet Beacon":
                  templates[i].Aliases = new[] { name, "FleetBeacon" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Robotics Bay":
                  templates[i].Aliases = new[] { name, "RoboticsBay" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Dark Shrine":
                  templates[i].Aliases = new[] { name, "DarkShrine" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 5;
                  break;

               case "Probe":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 1;
                  break;
               case "Mothership":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(4, 4);
                  templates[i].Priority = 4;
                  break;
               case "Zealot":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Sentry":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Stalker":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "High Templar":
                  templates[i].Aliases = new[] { name, "HighTemplar" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Dark Templar":
                  templates[i].Aliases = new[] { name, "DarkTemplar" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Archon":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Phoenix":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Void Ray":
                  templates[i].Aliases = new[] { name, "VoidRay" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Carrier":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Interceptor":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 1;
                  break;
               case "Observer":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Warp Prism":
                  templates[i].Aliases = new[] { name, "WarpPrism" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Immortal":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Colossus":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Protoss;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;

               case "Hatchery":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Lair":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Hive":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Extractor":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(12, 9);
                  templates[i].Priority = 3;
                  break;
               case "Spawning Pool":
                  templates[i].Aliases = new[] { name, "SpawningPool" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Evolution Chamber":
                  templates[i].Aliases = new[] { name, "EvolutionChamber" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 2;
                  break;
               case "Spore Crawler":
                  templates[i].Aliases = new[] { name, "SporeCrawler" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 3;
                  break;
               case "Roach Warren":
                  templates[i].Aliases = new[] { name, "RoachWarren" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Baneling Nest":
                  templates[i].Aliases = new[] { name, "BanelingNest" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Spine Crawler":
                  templates[i].Aliases = new[] { name, "SpineCrawler" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 3;
                  break;
               case "Hydralisk Den":
                  templates[i].Aliases = new[] { name, "HydraliskDen" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Infestation Pit":
                  templates[i].Aliases = new[] { name, "InfestationPit" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Spire":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Greater Spire":
                  templates[i].Aliases = new[] { name, "GreaterSpire" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Nydus Network":
                  templates[i].Aliases = new[] { name, "NydusNetwork" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Ultralisk Cavern":
                  templates[i].Aliases = new[] { name, "UltraliskCavern" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;

               case "Larva":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = false;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 1;
                  break;
               case "Egg":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = false;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 1;
                  break;
               case "Drone":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 1;
                  break;
               case "Overlord":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Overseer":
                  templates[i].Aliases = new[] { name, "OverlordCocoon" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Zergling":
                  templates[i].Aliases = new[] { name, "ZerglingBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 2;
                  break;
               case "Roach":
                  templates[i].Aliases = new[] { name, "RoachBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Hydralisk":
                  templates[i].Aliases = new[] { name, "HydraliskBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Infestor":
                  templates[i].Aliases = new[] { name, "InfestorBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Changeling":
                  templates[i].Aliases = new[] { name, "ChangelingZealot", "ChangelingMarineShield", "ChangelingMarine", "ChangelingZerglingWings", "ChangelingZergling"};
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Infested Terran":
                  templates[i].Aliases = new[] { name, "InfestedTerran", "InfestedTerransEgg", "InfestorTerran", "InfestorTerranBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Mutalisk":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Corruptor":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Brood Lord":
                  templates[i].Aliases = new[] { name, "BroodLord" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Ultralisk":
                  templates[i].Aliases = new[] { name, "UltraliskBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Queen":
                  templates[i].Aliases = new[] { name, "QueenBurrowed" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Zerg;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;

               case "Command Center":
                  templates[i].Aliases = new[] { name, "CommandCenter", "CommandCenterFlying" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Orbital Command":
                  templates[i].Aliases = new[] { name, "OrbitalCommand", "OrbitalCommandFlying" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Planetary Fortress":
                  templates[i].Aliases = new[] { name, "PlanetaryFortress" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(25, 25);
                  templates[i].Priority = 5;
                  break;
               case "Refinery":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(12, 9);
                  templates[i].Priority = 4;
                  break;
               case "Supply Depot":
                  templates[i].Aliases = new[] { name, "SupplyDepot", "SupplyDepotLowered" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 2;
                  break;
               case "Barracks":
                  templates[i].Aliases = new[] { name, "Barracks", "BarracksFlying" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Engineering Bay":
                  templates[i].Aliases = new[] { name, "EngineeringBay" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;
               case "Bunker":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;
               case "Missile Turret":
                  templates[i].Aliases = new[] { name, "MissileTurret" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 2;
                  break;
               case "Sensor Tower":
                  templates[i].Aliases = new[] { name, "SensorTower" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(6, 6);
                  templates[i].Priority = 2;
                  break;
               case "Ghost Academy":
                  templates[i].Aliases = new[] { name, "GhostAcademy" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Factory":
                  templates[i].Aliases = new[] { name, "Factory", "FactoryFlying" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Armory":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;
               case "Starport":
                  templates[i].Aliases = new[] { name, "Starport", "StarportFlying" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(18, 18);
                  templates[i].Priority = 5;
                  break;
               case "Fusion Core":
                  templates[i].Aliases = new[] { name, "FusionCore" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 5;
                  break;
               case "Reactor":
                  templates[i].Aliases = new[] { name, "BarracksReactor", "FactoryReactor", "StarportReactor" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;
               case "TechLab":
                  templates[i].Aliases = new[] { name, "BarracksTechLab", "FactoryTechLab", "StarportTechLab" };
                  templates[i].Building = true;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(9, 9);
                  templates[i].Priority = 3;
                  break;

               case "SCV":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 1;
                  break;
               case "MULE":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 2;
                  break;
               case "Marine":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 2;
                  break;
               case "Marauder":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 2;
                  break;
               case "Reaper":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 5;
                  break;
               case "Ghost":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(1, 1);
                  templates[i].Priority = 4;
                  break;
               case "Hellion":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 4;
                  break;
               case "Siege Tank":
                  templates[i].Aliases = new[] { name, "SiegeTank", "SiegeTankSieged" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Thor":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Viking":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;
               case "Medivac":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 3;
                  break;
               case "Raven":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 4;
                  break;
               case "Banshee":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 5;
                  break;
               case "Battlecruiser":
                  templates[i].Aliases = new[] { name };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Terran;
                  templates[i].Size = new Size(2, 2);
                  templates[i].Priority = 2;
                  break;

               case "Mineral Field":
                  templates[i].Aliases = new[] { name, "MineralField" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Unknown;
                  templates[i].Size = new Size(3, 2);
                  templates[i].Priority = 0;
                  break;
               case "Rich Mineral Field":
                  templates[i].Aliases = new[] { name, "RichMineralField" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Unknown;
                  templates[i].Size = new Size(3, 2);
                  templates[i].Priority = 0;
                  break;
               case "Vespene Geyser":
                  templates[i].Aliases = new[]
                     {
                        name, "VespeneGeyser", "SpacePlatformGeyser", "RichVespeneGeyser" 
                     };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = true;
                  templates[i].UnitRace = UnitTemplate.Race.Unknown;
                  templates[i].Size = new Size(4, 3);
                  templates[i].Priority = 0;
                  break;
               case "Xel'Naga Tower":
                  templates[i].Aliases = new[] { name, "XelNagaTower" };
                  templates[i].Building = false;
                  templates[i].VisibleStatus = false;
                  templates[i].UnitRace = UnitTemplate.Race.Unknown;
                  templates[i].Size = new Size(3, 3);
                  templates[i].Priority = 0;
                  break;
            }

            templates[i].Types = new int[templates[i].Aliases.Length];
            for (int j = 0, k = 0; j < UnitsTable.Table.Length; j++)
            {
               var j1 = j;
               if (templates[i].Aliases.Any(alias => UnitsTable.Table[j1] == alias))
               {
                  templates[i].Types[k++] = j;
               }
            }

            foreach (var alias in templates[i].Aliases)
            {
               for (var j = 0; j < UnitsTable.Table.Length; j++)
               {
                  if (UnitsTable.Table[j] != alias)
                  {
                     continue;
                  }

                  templates[i].DefaultType = j;
                  break;
               }

               if (templates[i].DefaultType != 0)
               {
                  break;
               }
            }

            templates[i].Imagefilename = "btn-";
            if (templates[i].Building)
            {
               templates[i].Imagefilename += "building-";
            }
            else
            {
               templates[i].Imagefilename += "unit-";
            }

            templates[i].Imagefilename += templates[i].UnitRace + "-";
            foreach (var imageFilename in
               templates[i].Aliases.Select(alias => @"Assets\Units\" + templates[i].Imagefilename + alias + ".png").Where(imageFilename => File.Exists(imageFilename)))
            {
               templates[i].Imagefilename = imageFilename;
               break;
            }

            if (!File.Exists(templates[i].Imagefilename))
            {
               templates[i].Imagefilename = @"Assets\Units\";
               if (templates[i].FrindlyName == "Orbital Command")
               {
                  templates[i].Imagefilename += "btn-building-terran-surveillancestation.png";
               }
               if (templates[i].FrindlyName == "Templar Archive")
               {
                  templates[i].Imagefilename += "btn-building-protoss-templararchives.png";
               }
            }

            try
            {
               templates[i].Image = FixedSize(Image.FromFile(templates[i].Imagefilename), 76, 76);
            }
            catch
            {
               templates[i].Image = FixedSize(new Bitmap(100, 100), 76, 76);
            }

            i++;
         }
      }

      /// <summary>
      /// Assign modelname to unit
      /// </summary>
      /// <param name="unit">The unit.</param>
      public static void GetModelName(ref Unit unit)
      {
         unit.ModelName = UnitsTable.Table[unit.UnitStruct.ModelNumber];
      }

      /// <summary>
      /// Assign template to unit
      /// </summary>
      /// <param name="unit">The unit.</param>
      public static void GetTemplate(ref Unit unit)
      {
         unit.Template = GetTemplate(unit.UnitStruct.ModelNumber);
      }

      /// <summary>
      /// Gets the template.
      /// </summary>
      /// <param name="modelNumber">The model number.</param>
      /// <returns>Unit template</returns>
      public static UnitTemplate.Template GetTemplate(int modelNumber)
      {
         foreach (var template in templates.Where(template => template.Types.Any(type => modelNumber == type)))
         {
            return template;
         }

         return new UnitTemplate.Template();
      }

      /// <summary>
      /// The fixed size.
      /// </summary>
      /// <param name="imgPhoto">The img photo.</param>
      /// <param name="width">The width.</param>
      /// <param name="height">The height.</param>
      /// <returns>Converted image</returns>
      private static Image FixedSize(Image imgPhoto, int width, int height)
      {
         var sourceWidth = imgPhoto.Width;
         var sourceHeight = imgPhoto.Height;
         const int SourceX = 0;
         const int SourceY = 0;
         var destX = 0;
         var destY = 0;

         float percent;
         var percentW = width / (float)sourceWidth;
         var percentH = height / (float)sourceHeight;
         if (percentH < percentW)
         {
            percent = percentH;
            destX = Convert.ToInt16((width - (sourceWidth * percent)) / 2);
         }
         else
         {
            percent = percentW;
            destY = Convert.ToInt16((height - (sourceHeight * percent)) / 2);
         }

         var destWidth = (int)(sourceWidth * percent);
         var destHeight = (int)(sourceHeight * percent);

         var image = new Bitmap(width, height, PixelFormat.Format24bppRgb);
         image.SetResolution(100, 100);

         var graphics = Graphics.FromImage(image);
         graphics.Clear(Color.Black);
         graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

         graphics.DrawImage(
            imgPhoto, 
            new Rectangle(destX, destY, destWidth, destHeight), 
            new Rectangle(SourceX, SourceY, sourceWidth, sourceHeight), 
            GraphicsUnit.Pixel);

         graphics.Dispose();
         return image;
      }

      #endregion
   }
}